<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/pc/jsp/common/common.jsp"%>
<%@ page language="java" import="com.limao.DBDataClass.CrowdUserAuthClass"%>
<% 
  String userid=(String)CacheClass.isLogin(request,response);
 if(CacheClass.getIntValue(userid)==0)
 {
 	out.println("<script language='JavaScript'>alert('您还没有登陆！');location.href=document.referrer;</script>"); //后退并刷新
 } 
 CrowdUserAuthClass user= WebFunction.getUserInfo(request,response);
 if(user==null)
 {
	 out.println("<script language='JavaScript'>alert('用户不存在，或被平台禁用，请联系客服！');window.history.back(-1);</script>");
	 return;
 } 
%>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <title>修改呢称</title>
    <style>
        body{
            width: 100%;
            height: 100%;
            background: transparent;
        }
    </style>
</head>
<body ontouchstart="">

<div class="loginBlock of bcf w100 h100">
    <div class="logintittle of tc pr">
        修改呢称<span class="pa cursor" id="close-x">&times;</span>
    </div>
    <div class="of jz" style="width: 454px;">
        <input type="text" name="" id="username" placeholder="<%=user.username %>" class="db br3" disabled="disabled" style="margin-top: 47px;cursor: not-allowed"/>
        <p class="t2 cred f14"></p>
        <input type="text" name="" id="usernameNew" placeholder="新呢称" class="db br3"/>
        <p class="t2 cred f14"></p>
        <div class="clearfix of" style="margin-top: 46px;">
            <input type="button" value="修&nbsp;改" name="" id="loginSub" class="cursor tc cf db btnBlue" onclick="Sub();" style="width: 100%"/>
        </div>
    </div>
</div><!--loginBlock-->
<div id="loadingfDiv" class="loadingfDiv pf w100 h100 db">
    <div class="w100 h100">
        <img src="pc/images/loading.gif" class="db jz" style="margin-top: 40%;">
    </div>
</div><!--loadinfDiv-->


<script>

    $(window).on("load", function() {
        $("#modifyNameBtn", parent.document).click(function () {
            $("#modifyNameIframeDiv", parent.document).slideDown();
            $(".theme-popover-mask", parent.document).fadeIn();

        });
        $("#close-x").click(function () {
            $("#modifyNameIframeDiv", parent.document).slideUp();
            $(".theme-popover-mask", parent.document).fadeOut();

        });
    });
    
    
    
     //判断和过滤
    function errorP(usernameNew,p,textVal){
       if(usernameNew == ""){
       		p.text(textVal);
       		return -1;
       }else if(usernameNew.indexOf("测试")!=-1||usernameNew.indexOf("91")!=-1||usernameNew.indexOf("狸猫")!=-1||usernameNew.indexOf("官方")!=-1){
       		p.text("为了防止侵权，用户昵称内不得含有‘测试’，‘七彩云购’，‘官方’等字样。谢谢合作");
       		return -1;
       }else{
       		p.text("");
       }
    }
    
    function Sub() {
        var usernameNew =$.trim($('#usernameNew').val());
        
  		if(errorP(usernameNew,$('#usernameNew').next('p'),'你还未填写新用户名')==-1){
        	return false;
        }
        
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m:114,name:usernameNew}),
            type: 'post',
            dataType: 'json',
            contentType:"application/json;charset=utf-8",
            success: function (data) {
            	console.log(data);
   	           if(data['state']==1)
	           {
	           		layer.alert(data.info);
	           		parent.location.reload();
	           }
	           else
	           {
	           		layer.alert(data.info);
	           }
	        },
            error: function (data) {
                alert(data.msg);
                return false;
            },
            complete: function () {
                $("#loadingfDiv").fadeOut();
            }
        });
    }
</script>
</body>
</html>